package com.thp.bigdata.secondarySort;

import org.apache.hadoop.io.WritableComparable;
import org.apache.hadoop.io.WritableComparator;

import com.thp.bigdata.secondarySort.OrderBean;

/**
 * 利用reduce端的ItemIdGroupingComparator来实现将相同的id的OrderBean看成相同的Key
 * @author 汤小萌
 *
 */
public class ItemIdGroupingComparator extends WritableComparator {
	
	// 这个构造方法是一定要有的
	// 传入作为key的bean的class类型，已经制定主要让框架做反射的实例对象
	protected ItemIdGroupingComparator() {
		super(OrderBean.class, true);
	}
	
	
	@Override
	public int compare(WritableComparable a, WritableComparable b) {
		OrderBean aBean = (OrderBean) a;
		OrderBean bBean = (OrderBean) b;
		// 相同的orderId就认为是相同的key
		return aBean.getItemId().compareTo(bBean.getItemId());
	}
}
